<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: product_listing.php 407 2014-01-18 16:10:44Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 407 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2014-01-18 16:10:44 +0000 (Sat, 18 Jan 2014) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */
$module_smarty = new Smarty();
$module_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');
$module_smarty->assign('BOXES_product_listing_top', $smarty->getTemplateVars('BOXES_product_listing_top'));

require_once(DIR_FS_INC.'inc.get_all_get_params.php');
require_once(DIR_FS_INC.'inc.get_vpe_name.php');

$products_listing_style = ($products_listing_style!=''?$products_listing_style:'product_listing');
if(!isset($_GET['per_site'])) $_GET['per_site'] = '20';
$listing = new page_break($listing_sql, $_GET['page'], true, 'index.php', $products_listing_style, $total_ids);

$module_content = array();
if($listing->result) {
	if(GROUP_CHECK == 'true')
		$group_check = " AND c.group_permission_".$_SESSION['customers_status']['customers_status_id']." = 1 ";

	$image = '';
	if(isset($_GET['brand']) && !empty($_GET['brand'])) {
		$brand = $db->db_query("SELECT 
									b.brand_name,
									b.brand_image,
									bi.brand_url,
									bi.brand_description 
								FROM 
									".TABLE_BRAND." b,
									".TABLE_BRAND_INFO." bi
								WHERE 
									b.brand_id = '".$_GET['brand']."' 
								AND
									bi.brand_id = '".$_GET['brand']."'
								AND
									bi.languages_id = '".(int)$_SESSION['languages_id']."'", true);

		if(!empty($brand->fields['brand_image'])) {
			$image = 'images/'.$brand->fields['brand_image'];
			$image_alt = $brand->fields['brand_name'];
			$dimension = get_img_size('images/'.$brand->fields['brand_image']);
		}
		$title = $brand->fields['brand_name'];
		$desc = $brand->fields['brand_description'];
		
		
	} else {
		$category = $db->db_query("SELECT
	                                	cd.categories_description,
	                                	cd.categories_description_2,
	                                	cd.categories_name,
				    					cd.categories_heading_title,
	                                	c.listing_template,
	                                	c.categories_image,
	                                	cd.categories_pic_alt
									FROM
										".TABLE_CATEGORIES." c
									INNER JOIN
										".TABLE_CATEGORIES_DESCRIPTION." cd 
										ON (cd.categories_id = '".$current_category_id."' AND cd.language_id = '".$_SESSION['languages_id']."')
	                                WHERE
										c.categories_id = '".$current_category_id."'".$group_check, true);
	
		if($category->fields['categories_image'] != '') {
			$image = DIR_WS_IMAGES.'categories/'.$category->fields['categories_image'];
			$image_alt = ($category->fields['categories_pic_alt'] !='' ? $category->fields['categories_pic_alt'] : $category->fields['categories_name']);
			$dimension = get_img_size($image);
		}
		$title = $category->fields['categories_heading_title'];
		$desc = $category->fields['categories_description'];
		$module_smarty->assign('CATEGORIES_DESCRIPTION_BOTTOM', $category->fields['categories_description_2']);
		$module_smarty->assign('CATEGORIES_NAME', $category->fields['categories_name']);
		if(isset($_GET['filter_id']) && !empty($_GET['filter_id'])) {
        	$brand = $db->db_query("SELECT brand_name FROM ".TABLE_BRAND." WHERE brand_id = '".$_GET['filter_id']."'", true);
			$title .= sprintf(BRAND_SORT_BY_CAT, $brand->fields['brand_name']);
        }
        
        include(DIR_WS_MODULES.'slider.php');
	}

	$module_smarty->assign('CATEGORIES_HEADING_TITLE', $title);
	$module_smarty->assign('CATEGORIES_IMAGE', $image);
	$module_smarty->assign('CATEGORIES_IMAGE_ALT', $image_alt);
	$module_smarty->assign('CATEGORIES_IMAGE_DIMENSION', $dimension);
	$module_smarty->assign('CATEGORIES_DESCRIPTION', $desc);

	$rows = 0;
	while(!$listing->sql_string->EOF) { $rows ++;
		if($listing->listName == 'mosaic' && empty($listing->sql_string->fields['products_image'])) {}
		else $module_content[] = $product->buildDataArray($listing->sql_string->fields, 'thumbnail', $listing->listData, $rows);
		$listing->sql_string->MoveNext();
	}

	$module_smarty->assign('module_content', $module_content);
	$module_smarty->assign('NAVIGATION', $listing->getLinks());
	$module_smarty->assign('LIST_NAME', $listing->page_name);
	$module_smarty->assign('CLASS_NAME', $listing->listName);

	$module_smarty->assign('language', $_SESSION['language']);
	
	include(DIR_WS_MODULES.'page_brand.php');
	include(DIR_WS_MODULES.'page_view_as.php');
	include(DIR_WS_MODULES.'page_per_site.php');
	include(DIR_WS_MODULES.'page_mulit_sort.php');
	
	if(isset($_GET['view']) && $_GET['view'] == 'infinite')
		$module_smarty->assign('infinite', true);
	
	$template_file = CURRENT_TEMPLATE.'/module/product_listing/'.$listing->listData['list_file'].'.html';
	if (!file_exists(DIR_FS_DOCUMENT_ROOT.'templates/'.$template_file))
  	$template_file = CURRENT_TEMPLATE.'/module/'.$listing->listData['list_file'].'.html';

	if(!CacheCheck()) {
		$module_smarty->caching = false;
		$module = $module_smarty->fetch($template_file);

	} else {
		$module_smarty->caching = true;
		$module_smarty->cache_lifetime = CACHE_LIFETIME;
		$module_smarty->cache_modified_check = CACHE_CHECK;
		$cache_id = $current_category_id.'_'.$_SESSION['language'].'_'.$_SESSION['customers_status']['customers_status_name'].'_'.$_SESSION['currency'].'_'.$_GET['brand'].'_'.$_GET['filter_id'].'_'.$_GET['tag'].'_'.$_GET['page'].'_'.$_GET['keywords'].'_'.$_GET['categories_id'].'_'.$_GET['pfrom'].'_'.$_GET['pto'].'_'.$_GET['x'].'_'.$_GET['y'].'_'.$_GET['per_site'].'_'.$_GET['view_as'];
		$module = $module_smarty->fetch($template_file, $cache_id);
	}
	
	$module_bak = $smarty->getTemplateVars('main_content');
	$smarty->assign('main_content', $module_bak.$module);

} else {
	$error = TEXT_PRODUCT_NOT_FOUND;
	include(DIR_WS_MODULES.FILENAME_ERROR_HANDLER);
}